package rank

import (
	"fmt"
	"github.com/hwcer/cosgo/redis"
	"time"
)

var (
	eraYear  int64
	doomsday int64
)

const layout = "2006-01-02 15:04:05-0700"

func Start(redis *redis.Client, sharId string, serverId int32) (err error) {
	if redis == nil {
		return fmt.Errorf("rank redis is nil")
	}
	if Redis != nil {
		return nil
	}
	Redis = redis
	Options.ShareId = sharId
	Options.ServerId = serverId

	et, _ := time.Parse(layout, Options.StartTime)
	eraYear = et.Unix()
	doomsday = eraYear + 100*365*24*60*60
	err = Master.start()
	return nil
}

func GetBucket(name string) *Bucket {
	return Master.Get(name)
}

func Register(name string, zMax, zScore int64, zType SortType, plugs Handle) {
	Master.Register(name, zMax, zScore, zType, plugs)
}
